package com.feijia.aijingjingus;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.SharedPreferences;
import android.magictools.cn.frameanimationdrawable.FrameByFrameAnimationDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.feijia.aijingjingus.view.Dialog;
import com.feijia.aijingjingus.util.PreferencesUtils;

import com.feijia.aijingjingus.util.PermissionUtil;
import com.xiasuhuei321.loadingdialog.manager.StyleManager;
import com.xiasuhuei321.loadingdialog.view.LoadingDialog;

//import cn.jpush.android.api.JPushInterface;
//import cn.sharesdk.framework.ShareSDK;
//import com.feijia.aijingjingus.GlobalHelper;
//import cn.smssdk.SMSSDK;

import static com.feijia.aijingjingus.GlobalHelper.GUserNum;
import static com.feijia.aijingjingus.GlobalHelper.IsFirstTimePlayAni;
import static com.feijia.aijingjingus.GlobalHelper.SkipLogo;
import static com.feijia.aijingjingus.GlobalHelper.isPlayedGuideAni;

public class MainActivity extends AppCompatActivity {
    Dialog dialog;
    private String[] requestPermissions = {
            android.Manifest.permission.BLUETOOTH,
            android.Manifest.permission.BLUETOOTH_ADMIN,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
            android.Manifest.permission.READ_EXTERNAL_STORAGE,
            android.Manifest.permission.ACCESS_COARSE_LOCATION,
            android.Manifest.permission.ACCESS_FINE_LOCATION};
    private PermissionUtil.PermissionTool permissionTool;
    RelativeLayout rlSelectAniMode,rlMianAni,rlMain,rlMainAniMode1,rlMainAniMode2;
    AnimatorSet set,set2,mode1StartSet,mode2StartSet;
    FrameByFrameAnimationDrawable FAD,FAD2;
    int timeSpan = 3000;
    int aniDuration =1500;
    FrameLayout flBtnMode1,flBtnMode2,flMainMode1,flMainMode2;
    Button btnSkip,speedlogin;
    Context context =this;
    boolean Ani1End=false;

    View dotted_line;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /*speedlogin=(Button)findViewById(R.id.speedlogin);
        speedlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), Smslogin.class);
                startActivity(intent);
            }
        });*/

        //安卓 6.0 动态权限申请
        if (Build.VERSION.SDK_INT>=23){
            permissionTool=new PermissionUtil.PermissionTool(new PermissionUtil.PermissionListener() {
                @Override
                public void allGranted() {

                }
            });
            permissionTool.checkAndRequestPermission(MainActivity.this, requestPermissions);

        }

        StyleManager s = new StyleManager();
        s.Anim(false).repeatTime(0).contentSize(-1).intercept(true);
        LoadingDialog.initStyle(s);

        //JPushInterface.setDebugMode(true);
        //JPushInterface.init(this);
        SharedPreferences sp = this.getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        GUserNum = sp.getString("USER_NAME", "");
        if (!GUserNum.isEmpty()){
            Intent intent =new Intent("controlCenterActivity");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
        }
        setContentView(R.layout.activity_main);


        /*Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);*/
        //ShareSDK.initSDK(this);
        //MobSDK.init(this,"1cdcd9cdbcb3a","cbb5d5139853e6e0431ecf41d69bb446");
        //SMSSDK.initSDK(MainActivity.this, "1ba6dfc33086a", "d926fdf92bf5e0ba4a257fa5de328740");
        //MobSDK.init(this, "26e60d71d9250","fa62a681a9d3fb8d609a91f60eb554f5");



        IsFirstTimePlayAni = sp.getBoolean("IsFirstTimePlayAni", true);
        final ImageView ivAlogo = (ImageView) findViewById(R.id.ivAlogo);
        final ImageView ivComLogo = (ImageView) findViewById(R.id.ivComLogo);
        rlMianAni = (RelativeLayout) findViewById(R.id.rlMianAni);
        rlMain = (RelativeLayout) findViewById(R.id.rlMain);
        rlSelectAniMode = (RelativeLayout) findViewById(R.id.rlSelectAniMode);
        //flBtnMode1=(FrameLayout)findViewById(R.id.flBtnMode1);
        flBtnMode2=(FrameLayout)findViewById(R.id.flBtnMode2);
        //flMainMode1=(FrameLayout)findViewById(R.id.flMainMode1);
        flMainMode2=(FrameLayout)findViewById(R.id.flMainMode2);
        //rlMainAniMode1=(RelativeLayout)findViewById(R.id.rlMainAniMode1);
        rlMainAniMode2=(RelativeLayout)findViewById(R.id.rlMainAniMode2);

        btnSkip=(Button)findViewById(R.id.btnSkip);
        //dotted_line=findViewById(R.id.dotted_line);





        if(SkipLogo) {
            aniDuration = 0;
            rlMianAni.setVisibility(View.GONE);
        }
        AnimatorSet set=new AnimatorSet();
        //ObjectAnimator ivAlogoOut =ObjectAnimator.ofFloat(ivAlogo,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator rlAniOut =ObjectAnimator.ofFloat(rlMianAni,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator rlAniBigX =ObjectAnimator.ofFloat(rlMianAni,"scaleX",1f,2f).setDuration(aniDuration);
        ObjectAnimator rlAniBigY =ObjectAnimator.ofFloat(rlMianAni,"scaleY",1f,2f).setDuration(aniDuration);
        ObjectAnimator btnSkipIn = ObjectAnimator.ofFloat(btnSkip,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator rlSelectAniModeIn =ObjectAnimator.ofFloat(rlSelectAniMode,"alpha",0f,1f).setDuration((long)(1.5*aniDuration));
        //ObjectAnimator ivAlogoBigX =ObjectAnimator.ofFloat(ivAlogo,"scaleX",1f,2f).setDuration(aniDuration);
        //ObjectAnimator ivAlogoBigY =ObjectAnimator.ofFloat(ivAlogo,"scaleY",1f,2f).setDuration(aniDuration);
        //ObjectAnimator ivComLogoBigX =ObjectAnimator.ofFloat(ivComLogo,"scaleX",1f,2f).setDuration(aniDuration);
        //ObjectAnimator ivComLogoBigY =ObjectAnimator.ofFloat(ivComLogo,"scaleY",1f,2f).setDuration(aniDuration);
        //set.play(rlAniOut).with(rlMainIn).with(ivAlogoBigX).with(ivAlogoBigY).with(ivComLogoBigX).with(ivComLogoBigY);
        set.play(rlAniOut).with(rlSelectAniModeIn).with(rlAniBigX).with(rlAniBigY).with(btnSkipIn);

        set.setStartDelay(1000);
        set.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                //rlMianAni.setVisibility(View.GONE);
                //rlMain.setVisibility(View.VISIBLE);
                GuideAniInit();
                rlSelectAniMode.setEnabled(true);
                Ani1End=true;
                if(isPlayedGuideAni)
                {
                    rlSelectAniMode.setVisibility(View.GONE);
                    rlMain.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        set.start();
        SkipLogo=true;



        if(isPlayedGuideAni)
        {
            rlSelectAniMode.setVisibility(View.GONE);
            rlMain.setVisibility(View.VISIBLE);
        }
    }

    public void onChangeLanguage(View view) {

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    public void onClickLogin(View view)
    {
        startActivity(new Intent("login_Activity"));
    }
    public void onClickFastScan(View view)

    {
        PreferencesUtils.putString(this,PreferencesUtils.PREFERENCE_NAME,"男");
        startActivity(new Intent("controlCenterActivity"));
    }
    public void onClickSignUp(View view)
    {
        startActivity(new Intent("signUp_Activity"));
    }
    public void onClickBleTest(View view)
    {
        startActivity(new Intent("BleTestActivity"));
    }

    public void onClickSkip(View view)
    {
        rlSelectAniMode.setVisibility(View.GONE);
        rlMain.setVisibility(View.VISIBLE);
    }
    public void onClickMode1(View view)
    {
        if(isPlayedGuideAni)
           return;
        if(!Ani1End)
            return;
        isPlayedGuideAni=true;
        set = new AnimatorSet();
        aniDuration =1000;
        mode1StartSet = new AnimatorSet();
        TextView tvAni1 =(TextView)findViewById(R.id.tvAni1);
        TextView tvAni2 =(TextView)findViewById(R.id.tvAni2);
        TextView tvAni3 =(TextView)findViewById(R.id.tvAni3);
        TextView tvAni4 =(TextView)findViewById(R.id.tvAni4);
        TextView tvAni5 =(TextView)findViewById(R.id.tvAni5);
        TextView tvAni1t =(TextView)findViewById(R.id.tvAni1t);
        TextView tvAni2t =(TextView)findViewById(R.id.tvAni2t);
        TextView tvAni3t =(TextView)findViewById(R.id.tvAni3t);
        TextView tvAni4t =(TextView)findViewById(R.id.tvAni4t);
        TextView tvAni5t =(TextView)findViewById(R.id.tvAni5t);
        //final ImageView iv = (ImageView)findViewById(R.id.anilist);
        //FAD = FrameByFrameAnimationDrawable.loadAnimation(this,R.drawable.animlist,true);
        //iv.setImageDrawable(FAD);

        ObjectAnimator flBtnMode1Out = ObjectAnimator.ofFloat(flBtnMode1,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator flMainMode1Down = ObjectAnimator.ofFloat(flMainMode1,"translationY",0,CalculateTranslationY(flMainMode1)).setDuration(aniDuration);
        ObjectAnimator btnSkipIn = ObjectAnimator.ofFloat(btnSkip,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator flMainMode2Out = ObjectAnimator.ofFloat(flMainMode2,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator dotted_lineOut = ObjectAnimator.ofFloat(dotted_line,"alpha",1f,0f).setDuration(aniDuration);

        mode1StartSet.play(btnSkipIn).with(flMainMode1Down).with(flMainMode2Out).with(dotted_lineOut);
        mode1StartSet.play(flBtnMode1Out).after(flMainMode1Down);
        mode1StartSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }
            @Override
            public void onAnimationEnd(Animator animation) {
                flBtnMode1.setVisibility(View.GONE);
                flMainMode2.setVisibility(View.GONE);

                rlMainAniMode1.setVisibility(View.VISIBLE);
                set.start();
            }
            @Override
            public void onAnimationCancel(Animator animation) {
                animation.cancel();
            }
            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });

        ObjectAnimator txt1In =ObjectAnimator.ofFloat(tvAni1,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt1Out =ObjectAnimator.ofFloat(tvAni1,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt2In =ObjectAnimator.ofFloat(tvAni2,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt2Out =ObjectAnimator.ofFloat(tvAni2,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt3In =ObjectAnimator.ofFloat(tvAni3,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt3Out =ObjectAnimator.ofFloat(tvAni3,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt4In =ObjectAnimator.ofFloat(tvAni4,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt4Out =ObjectAnimator.ofFloat(tvAni4,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt5In =ObjectAnimator.ofFloat(tvAni5,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt5Out =ObjectAnimator.ofFloat(tvAni5,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt1tIn =ObjectAnimator.ofFloat(tvAni1t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt1tOut =ObjectAnimator.ofFloat(tvAni1t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt2tIn =ObjectAnimator.ofFloat(tvAni2t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt2tOut =ObjectAnimator.ofFloat(tvAni2t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt3tIn =ObjectAnimator.ofFloat(tvAni3t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt3tOut =ObjectAnimator.ofFloat(tvAni3t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt4tIn =ObjectAnimator.ofFloat(tvAni4t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt4tOut =ObjectAnimator.ofFloat(tvAni4t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt5tIn =ObjectAnimator.ofFloat(tvAni5t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt5tOut =ObjectAnimator.ofFloat(tvAni5t,"alpha",1f,0f).setDuration(aniDuration);
        set.play(txt1In).with(txt1tIn);
        set.play(txt1Out).with(txt2In).with(txt1tOut).with(txt2tIn).after(txt1In).after(3400);
        set.play(txt2Out).with(txt3In).with(txt2tOut).with(txt3tIn).after(txt2In).after(11400);
        set.play(txt3Out).with(txt4In).with(txt3tOut).with(txt4tIn).after(txt3In).after(16400);
        set.play(txt4Out).with(txt5In).with(txt4tOut).with(txt5tIn).after(txt4In).after(22200);
        set.play(txt5Out).with(txt5tOut).after(txt5In).after(28800);
        set.setStartDelay(500);
        //set.start();
        set.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                //IsFirstTimePlayAni=false;
                //SharedPreferences.Editor editor = sp.edit();
                //editor.putBoolean("IsFirstTimePlayAni", IsFirstTimePlayAni);
                //editor.apply();
                //FAD = FrameByFrameAnimationDrawable.loadAnimation(context,R.drawable.animlist,true);
                //iv.setImageDrawable(FAD);
                //FAD.start();
            }
            @Override
            public void onAnimationEnd(Animator animation) {
                //IsFirstTimePlayAni=false;
                //SharedPreferences.Editor editor = sp.edit();
                //editor.putBoolean("IsFirstTimePlayAni", IsFirstTimePlayAni);
                //editor.apply();
                FAD.stop();
                //animation.setStartDelay(4000);
                animation.start();

            }
            @Override
            public void onAnimationCancel(Animator animation) {
                animation.cancel();
            }
            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        mode1StartSet.start();
    }

    void GuideAniInit(){
        set2 = new AnimatorSet();
        aniDuration =1000;
        mode1StartSet = new AnimatorSet();
        TextView tvAni21 =(TextView)findViewById(R.id.tvAni21);
        TextView tvAni22 =(TextView)findViewById(R.id.tvAni22);
        TextView tvAni23 =(TextView)findViewById(R.id.tvAni23);
        TextView tvAni24 =(TextView)findViewById(R.id.tvAni24);
        TextView tvAni25 =(TextView)findViewById(R.id.tvAni25);
        TextView tvAni21t =(TextView)findViewById(R.id.tvAni21t);
        TextView tvAni22t =(TextView)findViewById(R.id.tvAni22t);
        TextView tvAni23t =(TextView)findViewById(R.id.tvAni23t);
        TextView tvAni24t =(TextView)findViewById(R.id.tvAni24t);
        TextView tvAni25t =(TextView)findViewById(R.id.tvAni25t);

        final ImageView iv2 = (ImageView)findViewById(R.id.anilist2);
        FAD2 = FrameByFrameAnimationDrawable.loadAnimation(this,R.drawable.animlist2,true);
        iv2.setImageDrawable(FAD2);



        ObjectAnimator txt21In =ObjectAnimator.ofFloat(tvAni21,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt21Out =ObjectAnimator.ofFloat(tvAni21,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt22In =ObjectAnimator.ofFloat(tvAni22,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt22Out =ObjectAnimator.ofFloat(tvAni22,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt23In =ObjectAnimator.ofFloat(tvAni23,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt23Out =ObjectAnimator.ofFloat(tvAni23,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt24In =ObjectAnimator.ofFloat(tvAni24,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt24Out =ObjectAnimator.ofFloat(tvAni24,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt25In =ObjectAnimator.ofFloat(tvAni25,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt25Out =ObjectAnimator.ofFloat(tvAni25,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt21tIn =ObjectAnimator.ofFloat(tvAni21t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt21tOut =ObjectAnimator.ofFloat(tvAni21t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt22tIn =ObjectAnimator.ofFloat(tvAni22t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt22tOut =ObjectAnimator.ofFloat(tvAni22t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt23tIn =ObjectAnimator.ofFloat(tvAni23t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt23tOut =ObjectAnimator.ofFloat(tvAni23t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt24tIn =ObjectAnimator.ofFloat(tvAni24t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt24tOut =ObjectAnimator.ofFloat(tvAni24t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt25tIn =ObjectAnimator.ofFloat(tvAni25t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt25tOut =ObjectAnimator.ofFloat(tvAni25t,"alpha",1f,0f).setDuration(aniDuration);




        set2.play(txt21In).with(txt21tIn);
        set2.play(txt21Out).with(txt22In).with(txt21tOut).with(txt22tIn).after(txt21In).after(3400);
        set2.play(txt22Out).with(txt23In).with(txt22tOut).with(txt23tIn).after(txt22In).after(11850);
        set2.play(txt23Out).with(txt24In).with(txt23tOut).with(txt24tIn).after(txt23In).after(15350);
        set2.play(txt24Out).with(txt25In).with(txt24tOut).with(txt25tIn).after(txt24In).after(20750);
        set2.play(txt25Out).with(txt25tOut).after(txt25In).after(25700);
        set2.setStartDelay(500);
        //set2.start();
        set2.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                //IsFirstTimePlayAni=false;
                //SharedPreferences.Editor editor = sp.edit();
                //editor.putBoolean("IsFirstTimePlayAni", IsFirstTimePlayAni);
                //editor.apply();
                FAD2 = FrameByFrameAnimationDrawable.loadAnimation(context,R.drawable.animlist2,true);
                iv2.setImageDrawable(FAD2);
                FAD2.start();
            }
            @Override
            public void onAnimationEnd(Animator animation) {
                //IsFirstTimePlayAni=false;
                //SharedPreferences.Editor editor = sp.edit();
                //editor.putBoolean("IsFirstTimePlayAni", IsFirstTimePlayAni);
                //editor.apply();
                FAD2.stop();
                //animation.setStartDelay(4000);
                animation.start();

            }
            @Override
            public void onAnimationCancel(Animator animation) {
                animation.cancel();
            }
            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        set2.start();
    }

    public void onClickMode2(View view)
    {
        if(isPlayedGuideAni)
            return;
        if(!Ani1End)
            return;
        isPlayedGuideAni=true;

        set2 = new AnimatorSet();
        aniDuration =1000;
        mode1StartSet = new AnimatorSet();
        TextView tvAni21 =(TextView)findViewById(R.id.tvAni21);
        TextView tvAni22 =(TextView)findViewById(R.id.tvAni22);
        TextView tvAni23 =(TextView)findViewById(R.id.tvAni23);
        TextView tvAni24 =(TextView)findViewById(R.id.tvAni24);
        TextView tvAni25 =(TextView)findViewById(R.id.tvAni25);
        TextView tvAni21t =(TextView)findViewById(R.id.tvAni21t);
        TextView tvAni22t =(TextView)findViewById(R.id.tvAni22t);
        TextView tvAni23t =(TextView)findViewById(R.id.tvAni23t);
        TextView tvAni24t =(TextView)findViewById(R.id.tvAni24t);
        TextView tvAni25t =(TextView)findViewById(R.id.tvAni25t);

        mode2StartSet = new AnimatorSet();
        //ObjectAnimator flBtnMode2Out =ObjectAnimator.ofFloat(flBtnMode2,"alpha",1f,0f).setDuration(aniDuration);
        //mode2StartSet.play(flBtnMode2Out);

        ObjectAnimator flBtnMode2Out = ObjectAnimator.ofFloat(flBtnMode2,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator flMainMode2Down = ObjectAnimator.ofFloat(flMainMode2,"translationY",0,CalculateTranslationY(flMainMode2)).setDuration(aniDuration);
        ObjectAnimator btnSkipIn = ObjectAnimator.ofFloat(btnSkip,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator flMainMode1Out = ObjectAnimator.ofFloat(flMainMode1,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator dotted_lineOut = ObjectAnimator.ofFloat(dotted_line,"alpha",1f,0f).setDuration(aniDuration);

        mode2StartSet.play(btnSkipIn).with(flMainMode2Down).with(flMainMode1Out).with(dotted_lineOut);
        mode2StartSet.play(flBtnMode2Out).after(flMainMode2Down);

        mode2StartSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }
            @Override
            public void onAnimationEnd(Animator animation) {
                flBtnMode2.setVisibility(View.GONE);
                flMainMode1.setVisibility(View.GONE);
                rlMainAniMode2.setVisibility(View.VISIBLE);
                set2.start();
            }
            @Override
            public void onAnimationCancel(Animator animation) {
                animation.cancel();
            }
            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });


        final ImageView iv2 = (ImageView)findViewById(R.id.anilist2);
        FAD2 = FrameByFrameAnimationDrawable.loadAnimation(this,R.drawable.animlist2,true);
        iv2.setImageDrawable(FAD2);



        ObjectAnimator txt21In =ObjectAnimator.ofFloat(tvAni21,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt21Out =ObjectAnimator.ofFloat(tvAni21,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt22In =ObjectAnimator.ofFloat(tvAni22,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt22Out =ObjectAnimator.ofFloat(tvAni22,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt23In =ObjectAnimator.ofFloat(tvAni23,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt23Out =ObjectAnimator.ofFloat(tvAni23,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt24In =ObjectAnimator.ofFloat(tvAni24,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt24Out =ObjectAnimator.ofFloat(tvAni24,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt25In =ObjectAnimator.ofFloat(tvAni25,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt25Out =ObjectAnimator.ofFloat(tvAni25,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt21tIn =ObjectAnimator.ofFloat(tvAni21t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt21tOut =ObjectAnimator.ofFloat(tvAni21t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt22tIn =ObjectAnimator.ofFloat(tvAni22t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt22tOut =ObjectAnimator.ofFloat(tvAni22t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt23tIn =ObjectAnimator.ofFloat(tvAni23t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt23tOut =ObjectAnimator.ofFloat(tvAni23t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt24tIn =ObjectAnimator.ofFloat(tvAni24t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt24tOut =ObjectAnimator.ofFloat(tvAni24t,"alpha",1f,0f).setDuration(aniDuration);
        ObjectAnimator txt25tIn =ObjectAnimator.ofFloat(tvAni25t,"alpha",0f,1f).setDuration(aniDuration);
        ObjectAnimator txt25tOut =ObjectAnimator.ofFloat(tvAni25t,"alpha",1f,0f).setDuration(aniDuration);




        set2.play(txt21In).with(txt21tIn);
        set2.play(txt21Out).with(txt22In).with(txt21tOut).with(txt22tIn).after(txt21In).after(3400);
        set2.play(txt22Out).with(txt23In).with(txt22tOut).with(txt23tIn).after(txt22In).after(11850);
        set2.play(txt23Out).with(txt24In).with(txt23tOut).with(txt24tIn).after(txt23In).after(15350);
        set2.play(txt24Out).with(txt25In).with(txt24tOut).with(txt25tIn).after(txt24In).after(20750);
        set2.play(txt25Out).with(txt25tOut).after(txt25In).after(25700);
        set2.setStartDelay(500);
        //set2.start();
        set2.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                //IsFirstTimePlayAni=false;
                //SharedPreferences.Editor editor = sp.edit();
                //editor.putBoolean("IsFirstTimePlayAni", IsFirstTimePlayAni);
                //editor.apply();
                FAD2 = FrameByFrameAnimationDrawable.loadAnimation(context,R.drawable.animlist2,true);
                iv2.setImageDrawable(FAD2);
                FAD2.start();
            }
            @Override
            public void onAnimationEnd(Animator animation) {
                //IsFirstTimePlayAni=false;
                //SharedPreferences.Editor editor = sp.edit();
                //editor.putBoolean("IsFirstTimePlayAni", IsFirstTimePlayAni);
                //editor.apply();
                FAD2.stop();
                //animation.setStartDelay(4000);
                animation.start();

            }
            @Override
            public void onAnimationCancel(Animator animation) {
                animation.cancel();
            }
            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        mode2StartSet.start();
    }
    private int CalculateTranslationY(View view)
    {
        int width,height,densityDpi,viewWidth,viewHeight ;
        float density;
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        width = dm.widthPixels;         // 屏幕宽度（像素）
        height = dm.heightPixels;       // 屏幕高度（像素）
        density = dm.density;         // 屏幕密度（0.75 / 1.0 / 1.5）
        densityDpi = dm.densityDpi;     // 屏幕密度dpi（120 / 160 / 240）
        // 屏幕宽度算法:屏幕宽度（像素）/屏幕密度
        int screenWidth = (int) (width / density);  // 屏幕宽度(dp)
        int screenHeight = (int) (height / density);// 屏幕高度(dp)

        int[] location = new int[2];
        view.getLocationInWindow(location);

        viewWidth =View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
        viewHeight=View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
        view.measure(viewWidth,viewHeight);


        return height/2-location[1]-view.getHeight()/2;
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        permissionTool.onRequestPermissionResult(this, requestCode, permissions, grantResults);
    }

    public void onspeedlogin(View view) {
        //Toast.makeText(context, "", Toast.LENGTH_SHORT).show();
        startActivity(new Intent("TestPI"));
        Intent intent = new Intent();
        intent.setClass(this,TestPI.class);
        startActivity(intent);
    }
}
